﻿Public Class clsInhDrutWyslany
    Inherits clsDrutWyslany

#Region "Attributes"

    Private mvarDrut As clsInhTrDrut

#End Region

#Region "Properties"

    Public Property Drut As clsInhTrDrut
        Get
            Return mvarDrut
        End Get
        Set(ByVal value As clsInhTrDrut)
            mvarDrut = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()

        MyBase.New()
        mvarDrut = New clsInhTrDrut

    End Sub

    Public Sub New(ByVal Id As Integer, ByVal lvarDbHolder As clsDataBase)

        MyBase.New(Id, lvarDbHolder, VAR_ERROR_HANDLER)
        mvarDrut = New clsInhTrDrut(MyBase.DrutId, lvarDbHolder)

    End Sub

    Public Overloads Sub Save(ByVal lvarDbHolder As clsDataBase)
        MyBase.Save(lvarDbHolder, VAR_ERROR_HANDLER)
    End Sub

    Shared Function SprawdzWysylkeDrut(lvarDbHolder As clsDataBase, DrutId As Integer) As Boolean

        Dim lvarReader As OdbcDataReader = Nothing
        Dim lvarReturn As Integer

        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_drut_wyslany", 1, VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_zapytanie", DrutId.ToString())
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                lvarReturn = 1
            Else
                lvarReturn = 0
            End If

        End If

        Return CBool(lvarReturn)

    End Function

    Shared Function PobierzWyslanyDrutPaczka(lvarDbHolder As clsDataBase, Id As Integer) As DataTable

        Dim lvarReader As OdbcDataReader = Nothing
        Dim lvarReturn As DataTable

        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_drut_wyslany", 2, VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_id", Id.ToString())
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                lvarReturn = New DataTable
                lvarReturn.Load(lvarReader)
            End If

        End If

        Return lvarReturn

    End Function

#End Region

End Class
